/*
 * Niiuzu
 * Copyright (C) 2011  Thierry Nowak
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.niiuzu.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mvp4g.client.Mvp4gModule;

/**
 * Point d'entrée de l'application.
 */
public class NiiuzuModule implements EntryPoint {

	/**
	 * Définit le chargement de l'application suite au chargement du module.
	 */
	public void onModuleLoad() {
		Mvp4gModule module = getMvp4GModule();
		module.createAndStartModule();
		RootPanel rootPanel = getRootPanel();
		rootPanel.add((Widget) module.getStartView());
	}

	/**
	 * Récupère une instance de {@link Mvp4gModule}.
	 */
	private Mvp4gModule getMvp4GModule() {
		if (mockedMvp4gModule != null) {
			return mockedMvp4gModule;
		}
		return (Mvp4gModule) GWT.create(Mvp4gModule.class);
	}

	/**
	 * Retourne le {@link RootPanel} de l'application.
	 */
	private RootPanel getRootPanel() {
		if (mockedRootPanel != null) {
			return mockedRootPanel;
		}
		return RootPanel.get();
	}

	/* ********************************************************************** */
	/* ********************************************************************** */
	/* ********************************************************************** */

	private Mvp4gModule mockedMvp4gModule;
	private RootPanel mockedRootPanel;

	/**
	 * JUnit - Définit un mock pour {@link Mvp4gModule}.
	 */
	void setMockMvp4gModule(Mvp4gModule mockedMvp4gModule) {
		this.mockedMvp4gModule = mockedMvp4gModule;
	}

	/**
	 * JUnit - Définit un mock pour {@link RootPanel}.
	 */
	void setMockRootPanel(RootPanel mockedRootPanel) {
		this.mockedRootPanel = mockedRootPanel;
	}

}
